package com.example.project.utils;

import cn.hutool.crypto.SecureUtil;
import com.alibaba.ttl.TransmittableThreadLocal;
import com.example.project.vo.model.AuthUser;

import java.util.Objects;

/**
 * 存放 当前登入的 user信息
 */
public class SecurityUtils {
    private static ThreadLocal<AuthUser> RESOURCES = new TransmittableThreadLocal();

    public static void putUser(AuthUser authUser){
        RESOURCES.set(authUser);
    }

    public static AuthUser getUser(){
       return  RESOURCES.get();
    }

    public static void removeResources() {
        if (Objects.nonNull(RESOURCES)) {
            RESOURCES.remove();
        }
    }

    public static String getMd5(String password) {
        return SecureUtil.md5(password);
    }

}
